package com.fengke.cn.yejian11.adapter;

import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.fengke.cn.yejian11.R;
import com.fengke.cn.yejian11.config.Config;
import com.fengke.cn.yejian11.javabean.ClubVideo;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.fengke.cn.yejian11.config.Config.VIDEO_URL;

/**
 * Created by Administrator on 2017/10/3 0003.
 */

public class ClubCourseAdapter extends RecyclerView.Adapter {

    private List videoList;
    private LayoutInflater layoutInflater;
    private Context context;

    public ClubCourseAdapter(Context context,List courseList){
        this.context=context;
        this.videoList=courseList;
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView=LayoutInflater.from(context).inflate(R.layout.item_clubcourse,viewGroup,false);
        ClubCourseViewHolder holder=new ClubCourseViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        ClubCourseViewHolder clubCourseViewHolder= (ClubCourseViewHolder) viewHolder;
        ClubVideo.ClubvideoEntity entity= (ClubVideo.ClubvideoEntity) videoList.get(position);


        Uri videoUri=Uri.parse(Config.VIDEO_URL+entity.getVideopath());
        MediaController controller=new MediaController(context);
        controller.setMediaPlayer(clubCourseViewHolder.club_info_video);
        clubCourseViewHolder.club_info_video.setMediaController(controller);
        clubCourseViewHolder.club_info_video.setVideoPath(videoUri.toString());
        clubCourseViewHolder.club_info_video.start();
        final String address="http://172.24.10.175/workout/Uploads/"+entity.getThumb();
        if (!entity.getThumb().equals("")){
            Picasso.with(context).load(address).into(clubCourseViewHolder.videopic);
        }
    }

    @Override
    public int getItemCount() {
        return videoList.size();
    }

    public class ClubCourseViewHolder extends RecyclerView.ViewHolder {

        public ImageView videopic;
        public View itemView;
        VideoView club_info_video;
        public ClubCourseViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            videopic=(ImageView) itemView.findViewById(R.id.club_info_videopic);
            club_info_video=(VideoView)itemView.findViewById(R.id.club_info_video);
        }
    }
}
